//package cn.edu.zut.cs.Impl;
//
//import cn.edu.zut.cs.DAO.SCDAO;
//import cn.edu.zut.cs.Model.SC;
////对spring所需的执行语句进行引入
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.jdbc.core.BeanPropertyRowMapper;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.jdbc.core.RowMapper;
//import org.springframework.stereotype.Repository;
//
//import java.util.ArrayList;
//import java.util.List;
////对数据库需要操作的指令进行引入
//import java.sql.Connection;
//import java.sql.ResultSet;
//import java.sql.Statement;
////告诉spring的Service，我是你要实现的工具类，通过注解来声明位置，可以看到DAO的类
//@Repository
//public class SCDAOImpl implements SCDAO {
//JdbcTemplate jdbcTemplate;
//    @Override
//    public List<SC> getAllSCs()  {
//        List<SC> l = new ArrayList<>();
//
//        String sql = "select * from sc";
//        //mapper可以循环返回数据库的类的行数据，替代了
//        RowMapper<SC> rowMapper = new BeanPropertyRowMapper<>(SC.class);
//        l = jdbcTemplate.query(sql, rowMapper);
//        return l;
////        try {采用模板后，模板会处理异常的情况，减少了代码量
////            //获取连接，静态方法
////            Connection conn = MyConnection.getConnection();
////            String sql = "select * from sc";查询语句
////            //连接上面创建一个容器，交给了jdbc来处理
////            Statement stat = conn.createStatement();
////            ResultSet rs = stat.executeQuery(sql);
////            while(rs.next()) {这部分交给了Mapper来处理
////                SC s = new SC();
////                s.setSno(rs.getString("Sno"));
////                s.setCno(rs.getString("Cno"));
////                s.setGrade(rs.getInt("Grade"));
////                l.add(s);
////            }
////            conn.close();
////        } catch (Exception e) {
////            e.printStackTrace();
////        }
//    }
//
//    @Override
//    public void insert(SC b) {
//
//        String INSERT_SQL = "insert into sc(Sno,Cno ,Grade) values(?,?,?)";
//        Object[] arg = {b.getSno(), b.getCno(), b.getGrade()};
//        jdbcTemplate.update(INSERT_SQL, arg);
//    }
//    //以下可以删除
////    public void insert(SC s) {
////
////        try {
////            Connection conn = MyConnection.getConnection();
////
////            String sql = "insert into sc (Sno, Cno, Grade) values('"
////                    + s.getSno() + "','"
////                    + s.getCno() + "',"
////                    + s.getGrade() + ")";
//////            System.out.println(sql);
//////            下面对数据库的SQL的执行以及JDBC连接都会被JBDC模板所替代
////            Statement stat = conn.createStatement();
////            System.out.println(sql);
////            stat.executeUpdate(sql);
////            conn.close();
////        }catch (Exception e) {
////            e.printStackTrace();
////        }
////    }
//
//    @Override
//    public SC selectOne(SC s) {
//        SC bok = null;
//        String sql = "select * from sc where Sno=?";
//        bok= jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<SC>(SC.class),s.getSno());
//        //这里需要了解JDBC模板的查询方法，替代了下面的代码，减少了代码量
////        try {
////            Connection conn = MyConnection.getConnection();
////
////            String sql = "select * from sc where Sno='"
////                    + s.getSno() +"'";
////            Statement stat = conn.createStatement();
////            ResultSet rs = stat.executeQuery(sql);
////            while (rs.next()) {
////                s.setSno(rs.getString("Sno"));
////                s.setCno(rs.getString("Cno"));
////                s.setGrade(rs.getInt("Grade"));
////            }
////            conn.close();
////
////        }catch (Exception e) {}
//
//
//        return bok;
//    }
////    用set来注入JDBC模板
//@Autowired
//    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
//        this.jdbcTemplate = jdbcTemplate;
//    }
//}
